#include "process_management.h"
#include "uart.h"
#include "mips4kc.h"
#include "timer.h"
#include "kprint.h"
#include "splash.h"
#include "malta_lcd.h"
#include "dynamic_memory.h"

/* This function is the entry point of our operating system.
   It initializes the differents datastructure the kernel will use.
*/
void pornos(void) {
  status_reg_t and, or;
  and.reg = 0xFFFFFFFF;
  and.field.exl = 0; // EXL clear
  and.field.um = 0; // Kernel mode
  and.field.im = 0; // Clear IMs
  and.field.bev = 0; // normal exception vector
  and.field.erl = 0; // ERL clear
  
  or.reg = 0x00000000;
  or.field.ie = 1; //interrupts enabled
  or.field.im = 0x84; //useful interrupts enabled (those used by tty0 and the timer)
  kset_status(and.reg, or.reg);
  initialize_heap();
  initialize_processes_table();
  configure_uart();
  kprint_string(SPLASH_SCREEN);
  kprint_string("\n_____PORN-OS_____\n");
  kprint_string("PORN-OS OR No Operating System\n");
  /*malta_lcd_print_position(0,'P');
  malta_lcd_print_position(1,'0');  
  malta_lcd_print_position(2,'R');  
  malta_lcd_print_position(3,'N');*/
  kset_timer(TIME_QUANTUM); //sets the timer to interrupt after a time quantum
  //create_process(9,"fibonacci");
  //create_process(0,"uart_test", SYSTEM_ID);
  //create_process(0,"uart_test", SYSTEM_ID);
  //create_process(0,"uart_test", SYSTEM_ID);
  //int32_t params[4] = {0,1,2,3};
  //create_process(4, "fibonacci", SYSTEM_ID, NULL);
  // params[0] = (int32_t)s2;
  //create_process(4, "fibonacci", SYSTEM_ID, params);
  //create_process(8,"count", SYSTEM_ID, NULL);
  //create_process(3, "scroller", SYSTEM_ID, NULL);
  //create_process(17, "ring", SYSTEM_ID, NULL);
  create_process(3, "shell", SYSTEM_ID, NULL);
  while(1); //prevents the kernel from terminating
}





